************************************************************
*International Crisis Termination and Presidential Approval*
*         Kerry Chavez and James Wright                    *
************************************************************

*NOTE: The "ivreg2" package must be installed and Stata must be opened in Administrator mode.*
use full_sample, clear
tsset presidentid_crisis yearmonth

global president = "_Ipresident_*"
global c "miseryt1 ICB_dura ICB_viol strivalry coldwar nytimes_cum $president"
drop if start_and_terminate==1

***Baseline Models (Table 2, all columns in order from left to right)***
ivreg2 approve terminate, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve terminate $c firstyear elecyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate $c, cluster(yearmonth presidentid_crisis) bw(2)

***Election Year Models***
/*Table 3, column 1*/
ivreg2 approve terminate##elecyear $c firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
/*Figure 2, top left panel*/
margins, dydx(terminate) at(elecyear=(0 1)) atmeans
marginsplot, title("Moderator: Election Period") ytitle("Effect of Termination") ///
	xtitle("Election Period") yline(0) saving(PLOT_elecyear, replace)
/*Table A2, column 1*/
ivreg2 approve_detrend terminate##elecyear $c, cluster(yearmonth presidentid_crisis) bw(2)	

***New York Times Models***
/*Table 3, column 2*/
ivreg2 approve terminate##c.nytimes_cum $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
/*Figure 2, top right panel*/
margins, dydx(terminate) at(nytimes_cum=(0(0.1)18)) atmeans
marginsplot, addplot(hist nytimes_cum, ///
	freq yaxis(2) yscale(alt axis(2)) below start(0) width(0.5) legend(off)) ///
	title("Moderator: NY Times Coverage") ytitle("Effect of Termination") ///
	xtitle("NY Times Coverage") yline(0) saving(PLOT_nytimes_cum, replace)
/*Table A2, column 2*/
ivreg2 approve_detrend terminate##c.nytimes_cum $c, cluster(yearmonth presidentid_crisis) bw(2)

***Economic Misery Models***
/*Table 3, column 3*/
ivreg2 approve terminate##c.miseryt1 $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
/*Figure 2, bottom left panel*/
margins, dydx(terminate) at(miseryt1=(3.5(0.1)22)) atmeans
marginsplot, addplot(hist miseryt1, ///
	freq yaxis(2) yscale(alt axis(2)) below start(1) width(0.5) legend(off)) ///
	title("Moderator: Economic Misery") ytitle("Effect of Termination") ///
	xtitle("Economic Misery") yline(0) saving(PLOT_miseryt1, replace)
/*Table A2, column 3*/
ivreg2 approve_detrend terminate##c.miseryt1 $c, cluster(yearmonth presidentid_crisis) bw(2)

***Partisan Conflict Models***
/*Table 3, column 4*/
ivreg2 approve terminate##c.partisan_conflict_monthly $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
/*Figure 2, bottom right panel*/
margins, dydx(terminate) at(partisan_conflict_monthly=(60(1)180)) atmeans
marginsplot, addplot(hist partisan_conflict_monthly, ///
	freq yaxis(2) yscale(alt axis(2)) below start(50) width(0.5) legend(off)) ///
	title("Moderator: Partisan Conflict Index") ytitle("Effect of Termination") ///
	xtitle("Partisan Conflict Index") yline(0) saving(PLOT_partisan_conflict, replace)
/*combination of all graphs into Figure 2, if desired*/
graph combine PLOT_elecyear.gph PLOT_nytimes_cum.gph PLOT_miseryt1.gph PLOT_partisan_conflict.gph 
/*Table A2, column 4*/
ivreg2 approve_detrend terminate##c.partisan_conflict_monthly $c, cluster(yearmonth presidentid_crisis) bw(2)


************************************************************
*Robustness Checks with Two-Stage Residual Inclusion Models*
************************************************************

***Termination(1764 bootstrapping)***
gen ICB_dura2 = ICB_dura^2
gen ICB_dura3 = ICB_dura^3

/*Table A3, columns 1 and 2*/
capture program drop myboot
prog myboot, eclass
probit terminate ICB_globorg ICB_cenvio ICB_dura ICB_dura2 ICB_dura3
capture drop res
predict res, de
ivreg2 approve terminate $c firstyear elecyear term2 res, cluster(yearmonth presidentid_crisis) bw(2)
tempvar touse
tempname b V
matrix `b'=e(b)
matrix `V'=e(V)
quietly gen byte `touse' = e(sample)
ereturn post `b' `V', esample(`touse')
end
myboot

***Detrended Model***
/*Table A3, columns 3 and 4*/
capture program drop myboot
prog myboot, eclass
probit satisfy_us ICB_globorg ICB_cenvio ICB_dura ICB_dura2 ICB_dura3
capture drop res
predict res, de
ivreg2 approve_detrend terminate $c res, cluster(yearmonth presidentid_crisis) bw(2)
tempvar touse
tempname b V
matrix `b'=e(b)
matrix `V'=e(V)
quietly gen byte `touse' = e(sample)
ereturn post `b' `V', esample(`touse')
end
myboot

***Election Year***
/*Table A4, column 1*/
capture program drop myboot
prog myboot, eclass
probit terminate ICB_globorg ICB_cenvio ICB_dura ICB_dura2 ICB_dura3
capture drop res
predict res, de
ivreg2 approve terminate##elecyear $c firstyear term2 res, cluster(yearmonth presidentid_crisis) bw(2)
tempvar touse
tempname b V
matrix `b'=e(b)
matrix `V'=e(V)
quietly gen byte `touse' = e(sample)
ereturn post `b' `V', esample(`touse')
end
myboot

*New York Times Coverage*
/*Table A4, column 2*/
capture program drop myboot
prog myboot, eclass
probit terminate ICB_globorg ICB_cenvio ICB_dura ICB_dura2 ICB_dura3
capture drop res
predict res, de
ivreg2 approve terminate##c.nytimes_cum $c elecyear firstyear term2 res, cluster(yearmonth presidentid_crisis) bw(2)
tempvar touse
tempname b V
matrix `b'=e(b)
matrix `V'=e(V)
quietly gen byte `touse' = e(sample)
ereturn post `b' `V', esample(`touse')
end
myboot

***Economic Misery***
/*Table A4, column 3*/
capture program drop myboot
prog myboot, eclass
probit terminate ICB_globorg ICB_cenvio ICB_dura ICB_dura2 ICB_dura3
capture drop res
predict res, de
ivreg2 approve terminate##c.miseryt1 $c elecyear firstyear term2 res, cluster(yearmonth presidentid_crisis) bw(2)
tempvar touse
tempname b V
matrix `b'=e(b)
matrix `V'=e(V)
quietly gen byte `touse' = e(sample)
ereturn post `b' `V', esample(`touse')
end
myboot

***Partisan Conflict***
/*Table A4, column 4*/
capture program drop myboot
prog myboot, eclass
probit terminate ICB_globorg ICB_cenvio ICB_dura ICB_dura2 ICB_dura3
capture drop res
predict res, de
ivreg2 approve terminate##c.partisan_conflict_monthly $c elecyear firstyear term2 res, cluster(yearmonth presidentid_crisis) bw(2)
tempvar touse
tempname b V
matrix `b'=e(b)
matrix `V'=e(V)
quietly gen byte `touse' = e(sample)
ereturn post `b' `V', esample(`touse')
end
myboot
clear all


*************************************
*Robustness Checks for Crisis Sample*
*************************************

***Dropping crises nested within a broader war effort***
use full_sample, clear
tsset presidentid_crisis yearmonth
global president = "_Ipresident_*"
global c "miseryt1 ICB_dura ICB_viol strivalry coldwar nytimes_cum $president"
drop if start_and_terminate==1

*Vietnam War*
drop if ICB_crisno == 145
drop if ICB_crisno == 186
drop if ICB_crisno == 193
drop if ICB_crisno == 213
drop if ICB_crisno == 225
drop if ICB_crisno == 230
drop if ICB_crisno == 237
drop if ICB_crisno == 246
drop if ICB_crisno == 249
*Korean War*
drop if ICB_crisno == 140
drop if ICB_crisno == 274
*Gulf War/Iraq War/War or Terror/War in Afghanistan*
drop if ICB_crisno == 393
drop if ICB_crisno == 412
drop if ICB_crisno == 419
drop if ICB_crisno == 422
drop if ICB_crisno == 429
drop if ICB_crisno == 440
drop if ICB_crisno == 434

/*Table A5, column 1*/
ivreg2 approve terminate $c firstyear elecyear term2, cluster(yearmonth presidentid_crisis)
/*Table A5, column 2*/
ivreg2 approve_detrend terminate $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 1 and 2 respectively, row 1*/
ivreg2 approve terminate##elecyear $c firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##elecyear $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 1 and 2 respectively, row 2*/
ivreg2 approve terminate##c.nytimes_cum $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.nytimes_cum $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 1 and 2 respectively, row 3*/
ivreg2 approve terminate##c.miseryt1 $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.miseryt1 $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 1 and 2 respectively, row 4*/
ivreg2 approve terminate##c.partisan_conflict_monthly $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis)  bw(2)
ivreg2 approve_detrend terminate##c.partisan_conflict_monthly $c, cluster(yearmonth presidentid_crisis) bw(2)
clear all

***Controlling for instances in which a crisis is directly related to a previous crisis in the dataset***
use full_sample, clear
tsset presidentid_crisis yearmonth
global president = "_Ipresident_*"
global c "miseryt1 ICB_dura ICB_viol strivalry coldwar nytimes_cum $president"
drop if start_and_terminate==1

gen related=.
replace related = 1 if ICB_crisno == 166
replace related = 1 if ICB_crisno == 186
replace related = 1 if ICB_crisno == 193
replace related = 1 if ICB_crisno == 213
replace related = 1 if ICB_crisno == 225
replace related = 1 if ICB_crisno == 230
replace related = 1 if ICB_crisno == 237
replace related = 1 if ICB_crisno == 239
replace related = 1 if ICB_crisno == 246
replace related = 1 if ICB_crisno == 249
replace related = 1 if ICB_crisno == 274
replace related = 1 if ICB_crisno == 412
replace related = 1 if ICB_crisno == 419
replace related = 1 if ICB_crisno == 422
replace related = 1 if ICB_crisno == 429
replace related = 1 if ICB_crisno == 440
replace related = 1 if ICB_crisno == 441
replace related = 1 if ICB_crisno == 450
replace related = 1 if ICB_crisno == 459
replace related = 1 if ICB_crisno == 469
replace related = 0 if related ==.

/*Table A5, column 3*/
ivreg2 approve terminate $c firstyear elecyear term2, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A5, column 4*/
ivreg2 approve_detrend terminate $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 3 and 4 respectively, row 1*/
ivreg2 approve terminate##elecyear $c firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##elecyear $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 3 and 4 respectively, row 2*/
ivreg2 approve terminate##c.nytimes_cum $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.nytimes_cum $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 3 and 4 respectively, row 3*/
ivreg2 approve terminate##c.miseryt1 $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.miseryt1 $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 3 and 4 respectively, row 4*/
ivreg2 approve terminate##c.partisan_conflict_monthly $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis)  bw(2)
ivreg2 approve_detrend terminate##c.partisan_conflict_monthly $c, cluster(yearmonth presidentid_crisis) bw(2)
clear all

***Introducing war dummies***
use full_sample, clear
tsset presidentid_crisis yearmonth
global president = "_Ipresident_*"
global c "miseryt1 ICB_dura ICB_viol strivalry coldwar nytimes_cum $president"
drop if start_and_terminate==1

gen vietnamwar=.
replace vietnamwar = 1 if ICB_crisno == 145
replace vietnamwar = 1 if ICB_crisno == 186
replace vietnamwar = 1 if ICB_crisno == 193
replace vietnamwar = 1 if ICB_crisno == 213
replace vietnamwar = 1 if ICB_crisno == 225
replace vietnamwar = 1 if ICB_crisno == 230
replace vietnamwar = 1 if ICB_crisno == 237
replace vietnamwar = 1 if ICB_crisno == 246
replace vietnamwar = 1 if ICB_crisno == 249
replace vietnamwar = 0 if vietnamwar == .
gen cuba=.
replace cuba = 1 if ICB_crisno == 196
replace cuba = 1 if ICB_crisno == 239
replace cuba = 0 if cuba == .
gen taiwan=.
replace taiwan = 1 if ICB_crisno == 146
replace taiwan = 1 if ICB_crisno == 166
replace taiwan = 0 if taiwan == .
gen koreanwar=.
replace koreanwar = 1 if ICB_crisno == 140
replace koreanwar = 1 if ICB_crisno == 274
replace koreanwar = 0 if koreanwar ==.
gen iraq=.
replace iraq = 1 if ICB_crisno == 393
replace iraq = 1 if ICB_crisno == 412
replace iraq = 1 if ICB_crisno == 419
replace iraq = 1 if ICB_crisno == 422
replace iraq = 1 if ICB_crisno == 429
replace iraq = 1 if ICB_crisno == 440
replace iraq = 0 if iraq == .
gen dprk =.
replace dprk = 1 if ICB_crisno == 408
replace dprk = 1 if ICB_crisno == 441
replace dprk = 1 if ICB_crisno == 450
replace dprk = 1 if ICB_crisno == 459
replace dprk = 1 if ICB_crisno == 469
replace dprk = 0 if dprk == .

/*Table A5, column 5*/
ivreg2 approve terminate cuba taiwan iraq dprk koreanwar vietnamwar $c firstyear elecyear term2, cluster(yearmonth presidentid_crisis)
/*Table A5, column 6*/
ivreg2 approve_detrend terminate vietnamwar iraq dprk koreanwar cuba taiwan $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 5 and 6 respectively, row 1*/
ivreg2 approve terminate##elecyear vietnamwar iraq dprk koreanwar cuba taiwan $c firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##elecyear vietnamwar iraq dprk koreanwar cuba taiwan $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 5 and 6 respectively, row 2*/
ivreg2 approve terminate##c.nytimes_cum vietnamwar iraq dprk koreanwar cuba taiwan $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.nytimes_cum vietnamwar iraq dprk koreanwar cuba taiwan $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 5 and 6 respectively, row 3*/
ivreg2 approve terminate##c.miseryt1 vietnamwar iraq dprk koreanwar cuba taiwan $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.miseryt1 vietnamwar iraq dprk koreanwar cuba taiwan $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 5 and 6 respectively, row 4*/
ivreg2 approve terminate##c.partisan_conflict_monthly vietnamwar iraq dprk koreanwar cuba taiwan $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.partisan_conflict_monthly vietnamwar iraq dprk koreanwar cuba taiwan $c, cluster(yearmonth presidentid_crisis) bw(2)
clear all

***Ad hoc removal of crises of low salience based on authors' qualitative review and expertise***
use full_sample, clear
tsset presidentid_crisis yearmonth
global president = "_Ipresident_*"
global c "miseryt1 ICB_dura ICB_viol strivalry coldwar nytimes_cum $president"
drop if start_and_terminate==1

drop if ICB_crisno == 159
drop if ICB_crisno == 165
drop if ICB_crisno == 166
drop if ICB_crisno == 193
drop if ICB_crisno == 211
drop if ICB_crisno == 239
drop if ICB_crisno == 246

/*Table A5, column 7*/
ivreg2 approve terminate $c firstyear elecyear term2, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A5, column 8*/
ivreg2 approve_detrend terminate $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 7 and 8 respectively, row 1*/
ivreg2 approve terminate##elecyear $c firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##elecyear $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 7 and 8 respectively, row 2*/
ivreg2 approve terminate##c.nytimes_cum $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.nytimes_cum $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 7 and 8 respectively, row 3*/
ivreg2 approve terminate##c.miseryt1 $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.miseryt1 $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 7 and 8 respectively, row 4*/
ivreg2 approve terminate##c.partisan_conflict_monthly $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis)  bw(2)
ivreg2 approve_detrend terminate##c.partisan_conflict_monthly $c, cluster(yearmonth presidentid_crisis) bw(2)
clear all

***Dropping crises that overlap or where the crisis termination occurred within three months of a previous termination***
use full_sample, clear
tsset presidentid_crisis yearmonth
global president = "_Ipresident_*"
global c "miseryt1 ICB_dura ICB_viol strivalry coldwar nytimes_cum $president"
drop if start_and_terminate==1

drop if ICB_crisno == 144
drop if ICB_crisno == 165
drop if ICB_crisno == 186
drop if ICB_crisno == 225
drop if ICB_crisno == 230
drop if ICB_crisno == 303
drop if ICB_crisno == 411
drop if ICB_crisno == 441
drop if ICB_crisno == 448
drop if ICB_crisno == 470

/*Table A5, column 9*/
ivreg2 approve terminate $c firstyear elecyear term2, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A5, column 10*/
ivreg2 approve_detrend terminate $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 9 and 10 respectively, row 1*/
ivreg2 approve terminate##elecyear $c firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##elecyear $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 9 and 10 respectively, row 2*/
ivreg2 approve terminate##c.nytimes_cum $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.nytimes_cum $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 9 and 10 respectively, row 3*/
ivreg2 approve terminate##c.miseryt1 $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis) bw(2)
ivreg2 approve_detrend terminate##c.miseryt1 $c, cluster(yearmonth presidentid_crisis) bw(2)
/*Table A6, columns 9 and 10 respectively, row 4*/
ivreg2 approve terminate##c.partisan_conflict_monthly $c elecyear firstyear term2, cluster(yearmonth presidentid_crisis)  bw(2)
ivreg2 approve_detrend terminate##c.partisan_conflict_monthly $c, cluster(yearmonth presidentid_crisis) bw(2)
clear all

*************************************************
*Proof of Heteroskedasticity and Autocorrelation*
*************************************************
use full_sample, clear
tsset presidentid_crisis yearmonth
global president = "_Ipresident_*"
global c "miseryt1 ICB_dura ICB_viol strivalry coldwar nytimes_cum $president"
drop if start_and_terminate==1

***Heteroskedasticity Test***
/*Table 1, left panel*/
reg approve terminate $c 
predict resid, r
gen resid2 = resid^2
predict yhat, xb
predict se, stdp

twoway (hist approve, yaxis(2) fcolor(gs12) bcolor(gs10) bin(100)) /*
*/ (scatter resid2 yhat, msymbol(smcircle) mcolor(black) msize(small) yaxis(1)) /*
*/ (lowess resid2 yhat, lcolor(black)) /*
*/ , ytitle(Squared Residuals) subtitle("Heteroskedasticity Test", size(small)) /* 
*/ xtitle(Predicted Values of Y) legend(off) saving(figure1hetero, replace)

drop resid resid2 yhat se
reg approve_detrend terminate $c
estat hettest
estat imtest, white

***Autocorrelation Test***
/*Table 1, right panel*/
reg approve terminate $c
predict resid if e(sample), r
gen lag1_resid = L.resid
gen lag2_resid = L2.resid
gen lag3_resid = L3.resid
reg resid lag1_resid terminate $c2
reg resid lag1_resid lag2_resid terminate $c2
reg resid lag1_resid lag2_resid lag3_resid terminate $c2

twoway (hist lag1_resid, yaxis(2) fcolor(gs12) bcolor(gs10) bin(100)) /*
*/ (scatter resid lag1_resid, msymbol(smcircle) mcolor(black) msize(small) yaxis(1)) /*
*/ (lowess resid lag1_resid, lcolor(black)) /*
*/ , ytitle(Residuals at t) subtitle("Autocorrelation Test", size(small)) /* 
*/ xtitle(Residuals at t-1) legend(off) saving(figure1auto, replace)

capture drop resid lag1_resid lag2_resid lag3_resid
*AR(1) process is significant. AR(2) coefficient is small and less significant. AR(3) none

/*combination into Figure 1, if desired*/
graph combine figure1hetero.gph figure1auto.gph, saving(figure1, replace)

********************
*Summary Statistics*
********************
drop if ICB_crisno == .
/*Table A1*/
sum approve terminate nytimes_cum elecyear miseryt1 partisan_conflict_monthly ICB_dura ICB_viol strivalry coldwar firstyear term2
sum approve_detrend ICB_globorg ICB_cenvio
